<?php
class TagAction extends CommonAction {

	protected $currentModel=null;
	protected $tagArticle=null;
	protected $cacheData=array();

	public function _initialize()
	{
		parent::_initialize();
		$this->currentModel = D(MODULE_NAME);
		$this->tagArticle=M('TagArticle');
	}

	public function index()
	{
        $seoInfo['seo_title']="Tag集合";
        $seoInfo['seo_keywords']="热门标签";
        $seoInfo['seo_description']="林氏智造标签集合，通过标签筛选你喜欢的";
        $seo=seo($seoInfo);
        $this->assign('seo',$seo);		
		import ('@.ORG.Page');
    	$count=$this->currentModel->where($map)->count();
    	$page = new Page($count,70);
    	$datas=$this->currentModel->where($map)->limit($page->firstRow.','.$page->listRows)->order('hit DESC')->select();
    	$this->assign('page',$page->show());
    	$this->assign('datas',$datas);    		
		$this->display();    	
	}		
	
	public function view()
	{
		$code=trim($this->_get('code'));
		$where['code']=$code;
		$data=$this->currentModel->where($where)->find();
	  	if(empty($data))
	  	{
		  $this->error("数据不存在！","/");
	  	}
	  	$this->currentModel->where('id='.$data['id'])->setInc('hit',1);
	  	$seoInfo['seo_title']=$data['title'];
	  	$seoInfo['seo_description']='Tag：'.$data['title']."的文章";
	  	$seoInfo['seo_keywords']=$data['title'];
    	$seo=seo($seoInfo);
    	$this->assign('seo',$seo);
    	$this->assign('tagInfo',$data);
    	$where2['tag_id']=$data['id'];
    	$allArticleId='';
    	$allArticleIdArray=$this->tagArticle->field('value_id')->where($where2)->select();
    	if(!empty($allArticleIdArray))
    	{
    		foreach($allArticleIdArray as $d)
    		{
    			$allArticleId.=','.$d['value_id'];
    		}
    		$allArticleId=substr($allArticleId,1);
			import ('@.ORG.Page');
    		$map['id']=array('in',$allArticleId);
    		$map['stauts']=1;
    		$dataModel=D('Article');
    		$count=$dataModel->where($map)->count();
    		$page = new Page($count,C ('PAGE_LIMIT'));
    		$datas=$dataModel->where($map)->relation('Comment')->limit($page->firstRow.','.$page->listRows)->order('id DESC')->select();
    		$this->assign('page',$page->show());
    		$this->assign('datas',$datas);    		
    	}	
		$this->display();    	
	} 
}